package com.xinhua.erp.controller;

import com.xinhua.erp.pojo.Inventory;
import com.xinhua.erp.pojo.Result;
import com.xinhua.erp.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("inventory")
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;

    @GetMapping("{stockhouseId}/{page}/{size}")
    public Result findAllByType(@PathVariable Long stockhouseId,@PathVariable int page,@PathVariable int size){

        return inventoryService.findAllByStockhouseId(stockhouseId, page, size);

    }

    @PostMapping("search/{page}/{size}")
    public Result Search(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size){

        return inventoryService.Search(searchMap,page,size);

    }

    @GetMapping("{stockhouseId}/{productId}")
    public Result findBystockhouseIdAndproductId(@PathVariable long stockhouseId, @PathVariable long productId){

        return inventoryService.findBystockhouseIdAndproductId(stockhouseId, productId);
    }

    @PostMapping
    public Result save(@RequestBody Inventory inventory) { return inventoryService.save(inventory); }

    @PutMapping("{id}")
    public Result updateById(@PathVariable long id,@RequestBody Inventory inventory) { return inventoryService.updateById(id,inventory); }

    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable long id) { return inventoryService.deleteById(id); }




}
